﻿using System;
using System.ComponentModel;
using System.Globalization;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SLPropertyGrid.TypeConverters
{
    public class BooleanConverter : TypeConverter
    {
        // Fields
        //private static TypeConverter.StandardValuesCollection values;

        // Methods
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            return ((sourceType == typeof(string)) || base.CanConvertFrom(context, sourceType));
        }

        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value is string)
            {
                string str = ((string)value).Trim();
                try
                {
                    return bool.Parse(str);
                }
                catch (FormatException exception)
                {
                    throw new FormatException(string.Format("Unable to convert {0} - {1}", (string)value, "Boolean"), exception);
                }
            }
            return base.ConvertFrom(context, culture, value);
        }

        //public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        //{
        //    if (values == null)
        //    {
        //        values = new TypeConverter.StandardValuesCollection(new object[] { true, false });
        //    }
        //    return values;
        //}


    }

}
